/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import model.Case;

/**
 *
 * @author epulapp
 */
public class CaseVisible extends JPanel implements MouseListener {

    private Case cell;
    private Color etat = Color.WHITE;
    private boolean etatModel = false;
    private Graphique graph;

    public CaseVisible(Case c, Graphique g) {
        this.cell = c;
        this.graph = g;
        this.setBorder(BorderFactory.createLineBorder(Color.gray));
        this.setPreferredSize(new Dimension(12, 12));
        this.addMouseListener(this);
        //this.refresh();
    }

    public void refresh() {
        this.setBackground(this.etat);
    }

    public boolean getModelActif()
    {
        return this.etatModel;
    }
    public void setModelActif(boolean etatTemp) {
        this.etatModel = etatTemp;
    }

    public void testEtat() {
        if (etatModel) {
            this.etat = Color.red;
        } else {
            if (this.cell.getCell().getEtatN()) {
                this.etat = Color.black;
            } else {
                this.etat = Color.WHITE;
            }
        }

    }

    @Override
    public void mouseClicked(MouseEvent e) {
        this.graph.notifyChangeEtat();
        //this.cell.changeEtat();
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //this.setBackground(Color.red);
        this.graph.setPosY(this.cell.getPosY());
        this.graph.setPosX(this.cell.getPosX());
        //System.out.println(this.cell.getPosX()+"||"+this.cell.getPosY());
        this.graph.visuModel();
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //this.setBackground(this.etat);
    }
    
    public Case getCase()
    {
        return cell;
    }
}
